<?php

Class Photo {
	
	public $photoPath;
	
	function __construct($path) {
      $this->photoPath = $path;
    }
	
	public function getPhotoFile(){
		$fileArray = array();
		$iteratorDirectory = new DirectoryIterator($this->photoPath);
		foreach ($iteratorDirectory as $folderInfo) {
          if (!$folderInfo->isDot()){
		    $photoName = $folderInfo->getFilename();
		    $photoFolder = $this->photoPath . '/' . $folderInfo->getFilename();
		    $coverPic = $photoFolder . '/cover.jpg';
			if(!file_exists($coverPic)){
			  $iteratorFolder = new DirectoryIterator($photoFolder);
			  foreach ($iteratorFolder as $fileInfo){
			    if (!$fileInfo->isDot() & $fileInfo->getExtension()=='jpg'){
				  $coverPic = $coverPic = $photoFolder . '/' . $fileInfo->getFilename();
				  break;
				}
			  }
			}
			array_push($fileArray, array($photoName, $coverPic));
          }
        }
		return $fileArray;
	}
	
	public function getPhoto($folder){
		$photoArray = array();
		$photoFolder = $this->photoPath . '/' . $folder;
		$iteratorPhoto = new DirectoryIterator($photoFolder);
		foreach ($iteratorPhoto as $photoInfo) {
		  if (!$photoInfo->isDot() & $photoInfo->getExtension()=='jpg' & $photoInfo->getBasename('.jpg')!='cover'){
		    $photoName = $photoInfo->getFilename();
			$photoDir = $photoFolder . '/' . $photoName;
			array_push($photoArray, array($photoName, $photoDir));
		  }
		}
		return $photoArray;
	}
}

/*$photo = new Photo('../albums');
$array = $photo->getphotofile();
foreach($array as $file){
	echo $file[0] . '<br />';
}*/
/*$photo = new Photo('../albums');
$array = $photo->getPhoto('1_MayOne');
foreach($array as $file){
	echo $file[1] . '<br />';
}*/
?>